﻿Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports DotNetNuke.UI.UserControls
Imports DotNetNuke.UI

Namespace NVPortal.Modules.NVNews

    Public MustInherit Class Detail_Comment
        Inherits Entities.Modules.PortalModuleBase
#Region "Controls"
#End Region

#Region "Event Handlers"

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Not IsPostBack Then
                    Dim ctlNews As New NV_NewsController
                    Dim objNews As NV_NewsInfo
                    Dim objCache As Object = CType(Cache.Get("Tinchitet"), Object)
                    objNews = ctlNews.GetByIDShow(Request.Item("tin"))
                    If objCache Is Nothing Then
                        DataCache.SetCache("Tinchitet", objNews)
                        objNews = ctlNews.GetByIDShow(Request.Item("tin"))
                        If objNews.BinhLuan = True Then
                            Me.binhluan.Visible = True
                            Me.binhluan1.Visible = True
                        Else : Me.binhluan.Visible = False
                            Me.binhluan1.Visible = False
                        End If
                    Else
                        objCache = ctlNews.GetByIDShow(Request.Item("tin"))
                        If objCache.BinhLuan = True Then
                            Me.binhluan.Visible = True
                            Me.binhluan1.Visible = True
                        Else : Me.binhluan.Visible = False
                            Me.binhluan1.Visible = False
                        End If
                        
                    End If

                    Dim getCatID As String
                    getCatID = objNews.CategoryId
                    Dim idtintuc As String
                    idtintuc = Request.Item("tin")
                End If
                Dim ctlFeedback As New NV_NewsFeedbackController
                Me.dgrProducts.DataSource = ctlFeedback.GetByNewsId(Request.Item("tin"))
                Me.dgrProducts.DataBind()
            Catch ex As Exception
                'Me.imgNews.Visible = False
                ' Exception
                ProcessModuleLoadException(Me, ex)
            End Try
            trCaptcha.Visible = True
            'trCaptcha2.Visible = UseCaptcha

            ctlCaptcha.ErrorMessage = Localization.GetString("InvalidCaptcha", Localization.SharedResourceFile)
            ctlCaptcha.Text = Localization.GetString("CaptchaText", Localization.SharedResourceFile)

            BindDataFeed()
        End Sub
#End Region
        Protected Sub ibtSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtSend.Click
            If ctlCaptcha.IsValid Then
                If IsNumeric(Request.Item("tin")) Then
                    Dim ctlNewsFeedBack As New NV_NewsFeedbackController
                    ctlNewsFeedBack.Insert(Request.Item("tin"), Me.txtFullname.Text, Me.txtEmail.Text, Date.Now, "", Me.txtContent.Text, "", 1)
                    'Me.lbResult.Text = "Cập nhật tin thành công"
                    Response.Redirect(Request.RawUrl, True)
                End If
            End If
        End Sub

        Private Sub BindDataFeed()
            AddHandler Me.dgrProducts.PageIndexChanged, AddressOf dgrProducts_PageIndexChanged
            Dim objFeedback As New NV_NewsFeedbackController
            Me.dgrProducts.DataSource = objFeedback.GetByNewsId(Request.Item("tin"))
            Me.dgrProducts.AllowPaging = True
            Me.dgrProducts.PageSize = 7
            Me.dgrProducts.PagerStyle.Mode = PagerMode.NumericPages
            Me.dgrProducts.DataBind()
        End Sub
        'phan trang
        Private Sub InitializeComponent()
        End Sub
        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            InitializeComponent()
            MyBase.OnInit(e)
        End Sub
        Protected Sub dgrProducts_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgrProducts.ItemCommand
            Try
                Dim FeedbackId As String = Me.dgrProducts.DataKeys(e.Item.ItemIndex)
                If Session.Item(FeedbackId.ToString) Is Nothing Then
                    If e.CommandName = "uLike" Then
                        Dim ctlNews As New NV_NewsFeedbackController
                        ctlNews.UpdateuLike(FeedbackId)
                        BindDataFeed()
                    End If
                    If e.CommandName = "iLike" Then
                        Dim ctlNews As New NV_NewsFeedbackController
                        ctlNews.UpdateLike(FeedbackId)
                        BindDataFeed()
                    End If
                    Session.Add(FeedbackId.ToString, "tuycau")
                End If
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub
        Protected Sub dgrProducts_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgrProducts.PageIndexChanged
            Me.dgrProducts.CurrentPageIndex = e.NewPageIndex
            BindDataFeed()
        End Sub
        'Het phan trang
    End Class

End Namespace
